﻿using Newtonsoft.Json.Linq;
using System.Net;

class WeatherForecast
{
    static void Main(string[] args)
    {
        Console.WriteLine("欢迎使用天气预报应用！\n");
        Console.Write("请输入城市名: ");
        string city = Console.ReadLine();
        string url =
            string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&units=metric&appid={1}",
            city, "your_api_key_here");
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        string content = "";
        using (Stream stream = response.GetResponseStream())
        {
            StreamReader reader = new StreamReader(stream);
            content = reader.ReadToEnd();
        }
        JObject obj = JObject.Parse(content);
        string description = (string)obj["weather"][0]["description"];
        double temperature = (double)obj["main"]["temp"];
        double humidity = (double)obj["main"]["humidity"];
        double windspeed = (double)obj["wind"]["speed"];
        Console.WriteLine("\n{0}天气预报", city);
        Console.WriteLine("--------------\n");
        Console.WriteLine("天气情况: {0}", description);
        Console.WriteLine("气温: {0}°C", temperature);
        Console.WriteLine("湿度: {0}%", humidity);
        Console.WriteLine("风速: {0} 米/秒", windspeed);
        Console.ReadKey();
    }
}